package com.xneure.zkweb.view;

import java.beans.PropertyEditorSupport;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.xneure.utils.bean.GUID;
import com.xneure.zkweb.dao.SysUser;
import com.xneure.zkweb.dao.SysUserService;

@Controller
@ResponseBody
@RequestMapping("/ttt")
public class Demo{
	@Resource
	private SysUserService sysUserService;

	@RequestMapping("/msg")
	public List<SysUser> name(){
		List<SysUser> t;
		long time = System.nanoTime();
		t = sysUserService.getUsers();
		System.out.println(System.nanoTime() - time);
		return t;
	}

	@RequestMapping("/user")
	public SysUser user(){
		SysUser t;
		long time = System.nanoTime();
		t = sysUserService.getUser(GUID.valueOf("ACCE554FEBAD1CA47268E7FD3BBAE01D"));
		System.out.println(System.nanoTime() - time);
		return t;
	}

	@RequestMapping("/userAll")
	public List<SysUser> userAll(){
		List<SysUser> t;
		long time = System.nanoTime();
		t = sysUserService.getUserAll();
		System.out.println(System.nanoTime() - time);
		return t;
	}

	@RequestMapping("/add")
	public boolean add(){
		SysUser su = new SysUser();
		su.setName("ddd");
		su.setUserid(GUID.randomID());
		su.setCdate(new Date());
		// List<SysUser> list = new ArrayList<>();
		// for(int i=0;i<3;i++) {
		// SysUser s = new SysUser();
		// s.setName("ddd");
		// s.setUserid(GUID.randomID());
		// list.add(s);
		// }
		// su.setUs(list);
		sysUserService.insert(su);
		System.out.println();
		return true;
	}

	@RequestMapping("/ass")
	public void main(){
		System.out.println(132);
	}

	@InitBinder// 必须有一个参数WebDataBinder
	public void initBinder(WebDataBinder binder){
		binder.registerCustomEditor(GUID.class,new PropertyEditorSupport(){
			@Override
			public void setAsText(String text) throws IllegalArgumentException{
				super.setValue(GUID.valueOf(text));
			}
		});
	}
}
